unit Block;

interface

uses
  System.Windows.Forms, Settings, System.Drawing;

type
  TBlock = class(System.Windows.Forms.Label)
  private
    _marked : Boolean;
    _moveDirection : String;

    procedure SetMarked(value : Boolean);
  protected
    _MarkedImage : System.Drawing.Image;
    _UnmarkedImage : System.Drawing.Image;



  public
    property Marked : Boolean read _marked write SetMarked;
    property MoveDirection : String read _moveDirection write _moveDirection;

    constructor Create (width : Integer; height: Integer);
    function CanMove(direction : String) : Boolean;
  end;

implementation

constructor TBlock.Create(width : Integer; height : Integer);
begin
  inherited Create;

  self._UnmarkedImage := System.Drawing.Image.FromFile('Theme\markedblock.jpg');
  self._MarkedImage := System.Drawing.Image.FromFile('Theme\block.jpg');

  self.Width := width * TSettings.BlockWidth;
  self.Height := height * TSettings.BlockHeight;
  self.Marked := false;
  self.MoveDirection := '';
  self.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;

end;

procedure TBlock.SetMarked(value: Boolean);
begin
  self._marked := value;
  
  if (value) then
  begin
    self.BackgroundImage := self._MarkedImage;
  end
  else
  begin
    self.BackgroundImage := self._UnmarkedImage;
  end;
end;

function TBlock.CanMove(direction : String) : Boolean;
begin
  if not (direction = nil) and (direction.Length > 0) then
    result := (self.MoveDirection.IndexOf(direction) > -1)
  else
    result := false;
end;

end.
